<?php


require ROOT_PATH.'/Helper/admin_abstract.php';

class Action extends admin_abstract
{
    function delete($id)
    {
        _model('marquees')->delete(array('id'=>$id));

        $this->cache->ns('marquees')->delete();

        $this->redirect();
    }

    function update($id)
    {
        $info = _POST('info', array());
        if (empty($info['title']) || empty($info['link']) || empty($info['pic'])) {
            $this->msg('wrong request');
        }
        _model('marquees')->update(array('id'=>$id), $info);

        $this->cache->ns('marquees')->delete();
        
        $this->redirect();
    }

    function index()
    {
        if (Request::isPost()) {
            $info = _POST('info', array());
            if (empty($info['title']) || empty($info['link']) || empty($info['pic'])) {
                $this->msg('wrong request');
            }
            $info['add_time'] = time();
            _model('marquees')->create($info);

            $this->cache->ns('marquees')->delete();

            $this->redirect('admin/marquees_manage.htmlid?id='.$info['store_id']);
        } else {
            $id = _GET('id', 0);
            $data = _model('marquees')->getList(array('store_id'=>$id), 'ORDER BY add_time ASC');
            $this->view->assign('data', $data);
            $this->view->display('admin/marqueeads.html');
        }
    }
}

?>